﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TaskManager
{
    public partial class MessageForm : Form
    {
        public MessageForm()
        {
            InitializeComponent();
        }

        public string Mode = "信息";
        string remindId = "";     // 用于记录提示信息id

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        //--------------------------------
        // 显示一个消息记录弹窗
        public static void ShowRecord(string tittle, string content, string sender, string id, string sendtime)
        {
            Show("(" + sendtime + ")" + tittle, content, sender, id, "信息记录");
        }

        // 显示一个消息记录弹窗
        public static void ShowRecord(Data_Remind remind)
        {
            string sender = remind.uaccount.Equals(remind.urealname) ? remind.uaccount : (remind.uaccount + "(" + remind.urealname + ")");
            ShowRecord(remind.title, remind.content, sender, remind.id, remind.sendTime);
        }

        //--------------------------------
        // 显示一个任务消息弹窗
        public static void ShowTask(string tittle, string content, string sender, string id, string assignedate, string assignedTo, string status)
        {
            Show(tittle + " (指派给：" + assignedTo + ") - " + status, content, sender, id, "任务信息");
        }

        // 显示一个任务消息弹窗
        public static void ShowTask(Data_Task remind)
        {
            //string sender = remind.uaccount.Equals(remind.urealname) ? remind.uaccount : (remind.uaccount + "(" + remind.urealname + ")");
            ShowTask(remind.name, remind.desc, remind.openedBy, remind.id, remind.assignedDate, remind.assignedTo, remind.status);
        }


        //--------------------------------
        // 显示一个需求信息弹窗
        public static void ShowDemand(string tittle, string content, string sender, string id, string assignedate, string assignedTo)
        {
            Show(tittle + " (指派给：" + assignedTo + ", " + assignedate + ")", content, sender, id, "需求信息");
        }

        // 显示一个需求信息弹窗
        public static void ShowDemand(Data_Demand demand)
        {
            //string sender = remind.uaccount.Equals(remind.urealname) ? remind.uaccount : (remind.uaccount + "(" + remind.urealname + ")");
            ShowDemand(demand.title, demand.title, demand.openedBy, demand.id, demand.assignedDate, demand.assignedTo);
        }

        //--------------------------------
        // 显示一个任务消息弹窗
        public static void ShowBug(string tittle, string content, string sender, string id, string assignedate, string assignedTo, string status)
        {
            Show(tittle + " (指派给：" + assignedTo + ") - " + status, content, sender, id, "Bug信息");
        }

        // 显示一个任务消息弹窗
        public static void ShowBug(Data_Bug bug)
        {
            //string sender = remind.uaccount.Equals(remind.urealname) ? remind.uaccount : (remind.uaccount + "(" + remind.urealname + ")");
            ShowBug(bug.title, bug.steps, bug.openedBy, bug.id, bug.assignedDate, bug.assignedTo, bug.status);
        }


        //--------------------------------
        // 显示一个测试消息弹窗
        public static void ShowTesttask(string tittle, string content, string sender, string id, string assignedate, string assignedTo, string status)
        {
            Show(tittle + " (指派给：" + assignedTo + ") - " + status, content, sender, id, "测试信息");
        }

        // 显示一个任务消息弹窗
        public static void ShowTesttask(Data_Testtask Testtask)
        {
            //string sender = remind.uaccount.Equals(remind.urealname) ? remind.uaccount : (remind.uaccount + "(" + remind.urealname + ")");
            ShowTesttask(Testtask.name, Testtask.desc, Testtask.build, Testtask.id, Testtask.begin, Testtask.owner, Testtask.status);
        }


        //--------------------------------        
        // 显示一个消息提示弹窗
        public static void Show(string tittle, string content, string sender, string id, string Mode)
        {
            MessageForm form = new MessageForm();

            if (!Mode.Equals(""))
            {
                form.Mode = Mode;
                form.Text = Mode;
            }

            form.label_tittle.Text = tittle;
            form.textBox_content.Text = "\r\n" + content;
            form.label_sender.Text = sender;

            form.remindId = id; // 记录提示的任务信息id

            form.Show();        // 显示提示信息
        }

        // 显示一个消息提示弹窗
        public static void ShowRemind(Data_Remind remind)
        {
            if (remind != null)
            {
                string sender = remind.uaccount.Equals(remind.urealname) ? remind.uaccount : (remind.uaccount + "(" + remind.urealname + ")");
                Show(remind.title, remind.content, sender, remind.id, "信息");
            }
        }

        private void MessageForm_Load(object sender, EventArgs e)
        {
            FormTool.RestoreFormInfo(this);
        }

        private void MessageForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormTool.saveFormInfo(this);        // 保存界面信息

            if (Mode.Equals("信息"))                        // 关闭提示信息界面后，记录当前提示信息的id
            {
                loginForm.Remind_Ids.saveIdData(remindId);
                loginForm.savePeriodRemind_IdData(remindId);// 记录当前提示的周期性提示信息状态
            }
            else if (Mode.Equals("任务信息"))
                loginForm.Task_Ids.saveIdData(remindId);    // 记录当前的任务状态信息
            else if (Mode.Equals("需求信息"))
                loginForm.Demand_Ids.saveIdData(remindId);  // 关闭需求信息界面后，记录当前提示信息的id


            else if (Mode.Equals("Bug信息"))
                loginForm.Bug_Ids.saveIdData(remindId);     // 记录当前显示信息的id
            else if (Mode.Equals("测试信息"))
                loginForm.Testtask_Ids.saveIdData(remindId);// 记录当前显示信息的id
        }
    }
}
